def getvel():
    import sys
    import time
    if __name__=="__main__":

        try:
            amass=float(sys.argv[1])
        except:
            print("Specify input mass, dir[0], dir[1], dir[2], Recoil_energy.")
            sys.exit(2)

        try:
            dx=float(sys.argv[2])
        except:
            print("Specify input mass, dir[0], dir[1], dir[2], Recoil_energy.")
            sys.exit(2)

        try:
            dy=float(sys.argv[3])
        except:
            print("Specify input mass, dir[0], dir[1], dir[2], Recoil_energy.")
            sys.exit(2)

        try:
            dz=float(sys.argv[4])
        except:
            print("Specify input mass, dir[0], dir[1], dir[2], Recoil_energy.")
            sys.exit(2)

        try:
            rec=float(sys.argv[5])
        except:
            print("Specify input mass, dir[0], dir[1], dir[2], Recoil_energy.")
            sys.exit(2)
    else:
        raise Exception("Specify using argument. Not prepared.")

    t0=time.time()
    lfn="log%.0f" % t0

    import math
    amu2ev=931.494e+6 # eV/c2
    vc=2.99792458e+8 # m/sec
    vc=vc*0.01 # A/ps
    # rec in eV, amass in amu
    k=math.sqrt((2.0*rec*vc**2)/(amass*amu2ev*(dx**2+dy**2+dz**2)))
    vx=k*dx
    vy=k*dy
    vz=k*dz

    # Print result
    str2=" E: %.3f eV, vx: %.3e, vy: %.3e, vz: %.3e in A/ps (Dir: %d %d %d)\n"
    lfp=open(lfn,'w')
    lfp.write(str2 % (rec,vx,vy,vz,dx,dy,dz))
    sys.stdout.write(str2 % (rec,vx,vy,vz,dx,dy,dz))
    lfp.close()

getvel()
